from appium.webdriver.common.appiumby import AppiumBy

from appium_qiyeweixin.page_object.public.nav_menu import NavMenu


class WorkbenchPage(NavMenu):
    __CLOCK_IN = (AppiumBy.XPATH, "//*[@text='打卡']")
    __CLICK_CLOCK_IN = (AppiumBy.XPATH, "//*[contains(@text, '次外出')]/..")
    __CONFIRM_PUNCH_OUT = (AppiumBy.XPATH, "//*[@text='外出打卡成功']")

    # 打卡页面
    def clock_in(self):
        element = self.do_swipe(self.__CLOCK_IN)
        element.click()

        return self

    # 外出打卡
    def clock_in_punch_out(self):
        coordinate = {
            "start_x": 0.7,
            "start_y": 0.5,
            "end_x": 0.3,
            "end_y": 0.5
        }
        self.do_swipe_sliding_around(coordinate)
        self.do_ele_click(self.__CLICK_CLOCK_IN)

        return self

    # 确认外出打卡成功
    def confirm_punch_out(self):
        element = self.do_find(self.__CONFIRM_PUNCH_OUT)

        return element.text
